<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getNaveMenu();
                $user=pdo_get('users',array('username'=>$_W['username']));
                $uniacid=pdo_get('users_permission',array('uid'=>$user['uid']));

$where=' WHERE uniacid=:uniacid ';
$data[':uniacid']=$uniacid['uniacid'];

$todaytime=strtotime(date('Y-m-d',time()));
$yesterdaytime=strtotime(date('Y-m-d',time()))-86400;
$weektime=strtotime(date('Y-m-d',time()))-7*86400;
$monthtime=strtotime(date('Y-m-d',time()))-30*86400;
$smonthtime=strtotime(date('Y-m-d',time()))-90*86400;


$store=pdo_get('zh_yjm_store',array('admin'=>$_W['username']));
$cusmember=pdo_getall('zh_yjm_cusmember', array('uniacid' => $uniacid['uniacid'],'store_id' => $store['id']), array(), '', 'sort DESC');

$weeks=array();
$weeksx=array();
$months=array();
$monthx=array();
$smonths=array();
$smonthx=array();
$qjs=array();
$qjx=array();
for ($i=0; $i <count($cusmember) ; $i++) { //单人充值记录(d)
	// pdo_get('zh_yjm_moneyinfo', array('m_id' => $cusmember[$i]['id'], 'uniacid' => $uniacid['uniacid']), array('sum(money) as total_money'));
	$tmd[$i]=pdo_fetchall("SELECT * FROM ".tablename('zh_yjm_moneyinfo').$where." and m_id=".$cusmember[$i]['id']." and time >=FROM_UNIXTIME(".$weektime.")",$data);
	$tmdx[$i]=pdo_fetchall("SELECT * FROM ".tablename('zh_yjm_moneyinfox').$where." and m_id=".$cusmember[$i]['id']." and time >=FROM_UNIXTIME(".$weektime.")",$data);
	for ($j=0; $j <count($tmd[$i]) ; $j++) { 
		array_push($weeks, $tmd[$i][$j]);
	}
	for ($k=0; $k <count($tmdx[$i]) ; $k++) { 
		array_push($weeksx, $tmdx[$i][$k]);
	}

	$mtmd[$i]=pdo_fetchall("SELECT * FROM ".tablename('zh_yjm_moneyinfo').$where." and m_id=".$cusmember[$i]['id']." and time >=FROM_UNIXTIME(".$monthtime.")",$data);
	$mtmdx[$i]=pdo_fetchall("SELECT * FROM ".tablename('zh_yjm_moneyinfox').$where." and m_id=".$cusmember[$i]['id']." and time >=FROM_UNIXTIME(".$monthtime.")",$data);
	for ($j=0; $j <count($mtmd[$i]) ; $j++) { 
		array_push($months, $mtmd[$i][$j]);
	}
	for ($k=0; $k <count($mtmdx[$i]) ; $k++) { 
		array_push($monthx, $mtmdx[$i][$k]);
	}

	$smtmd[$i]=pdo_fetchall("SELECT * FROM ".tablename('zh_yjm_moneyinfo').$where." and m_id=".$cusmember[$i]['id']." and time >=FROM_UNIXTIME(".$smonthtime.")",$data);
	$smtmdx[$i]=pdo_fetchall("SELECT * FROM ".tablename('zh_yjm_moneyinfox').$where." and m_id=".$cusmember[$i]['id']." and time >=FROM_UNIXTIME(".$smonthtime.")",$data);
	for ($j=0; $j <count($smtmd[$i]) ; $j++) { 
		array_push($smonths, $smtmd[$i][$j]);
	}
	for ($k=0; $k <count($smtmdx[$i]) ; $k++) { 
		array_push($smonthx, $smtmdx[$i][$k]);
	}
}
$weekmoneys=0;
for ($i=0; $i <count($weeks) ; $i++) { 
	$weekmoneys+=$weeks[$i]['money'];
}
$weekmoneysx=0;
for ($i=0; $i <count($weeksx) ; $i++) { 
	$weekmoneysx+=$weeksx[$i]['money'];
}
$monthmoneys=0;
for ($i=0; $i <count($months) ; $i++) { 
	$monthmoneys+=$months[$i]['money'];
}
$monthmoneysx=0;
for ($i=0; $i <count($monthx) ; $i++) { 
	$monthmoneysx+=$monthx[$i]['money'];
}
$smonthmoneys=0;
for ($i=0; $i <count($smonths) ; $i++) { 
	$smonthmoneys+=$smonths[$i]['money'];
}
$smonthmoneysx=0;
for ($i=0; $i <count($smonthx) ; $i++) { 
	$smonthmoneysx+=$smonthx[$i]['money'];
}


if($_GPC['time']){
	// var_dump($_GPC['time']);die;
    $start=strtotime($_GPC['time']['start']);
    $end=strtotime($_GPC['time']['end']);
    // $where.=" and timesjc >={$start} and timesjc<={$end}";
    for ($i=0; $i <count($cusmember) ; $i++) { 
		$qjtmd[$i]=pdo_fetchall("SELECT * FROM ".tablename('zh_yjm_moneyinfo').$where." and m_id=".$cusmember[$i]['id']." and time >=FROM_UNIXTIME(".$start.") and time <=FROM_UNIXTIME(".$end.")",$data);
		$qjtmdx[$i]=pdo_fetchall("SELECT * FROM ".tablename('zh_yjm_moneyinfox').$where." and m_id=".$cusmember[$i]['id']." and time >=FROM_UNIXTIME(".$start.") and time <=FROM_UNIXTIME(".$end.")",$data);
		for ($j=0; $j <count($qjtmd[$i]) ; $j++) { 
			array_push($qjs, $qjtmd[$i][$j]);
		}
		for ($k=0; $k <count($qjtmdx[$i]) ; $k++) { 
			array_push($qjx, $qjtmdx[$i][$k]);
		}
	}

	$jqmoneys=0;
	for ($i=0; $i <count($qjs) ; $i++) { 
		$jqmoneys+=$qjs[$i]['money'];
	}
	$jqmoneysx=0;
	for ($i=0; $i <count($qjx) ; $i++) { 
		$jqmoneysx+=$qjx[$i]['money'];
	}
}



include $this->template('web/cussell');